package com.csu.tingtian.controller;

import com.csu.tingtian.common.CommonResponse;
import com.csu.tingtian.service.ProduceOrderService;
import com.csu.tingtian.vo.ProduceOrder;
import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/produceorder/")
public class ProduceOrderController {
    @Autowired
    private ProduceOrderService produceOrderService;

    //获取系统中所有的农产品订单
    @GetMapping("produceorders")
    @ResponseBody
    public CommonResponse<List<ProduceOrder>> getAllProducorder(){
        return produceOrderService.getAllProduceOrder();
    }
    //根据用户名获取农产品订单
    @GetMapping("{username}/produceorders")
    @ResponseBody
    public CommonResponse<List<ProduceOrder>> getProduceOrderByUserName(@PathVariable("username")String userName){
        return produceOrderService.getProduceOrderByUserName(userName);
    }
    //根据orderid查找农产品订单
    @GetMapping("{orderid}")
    @ResponseBody
    public CommonResponse<ProduceOrder> getProduceOrderByOrderId(@PathVariable("orderid")int orderId){
        return produceOrderService.getProduceOrderByOrderId(orderId);
    }
    //插入一条农产品订单
    @PostMapping("produceorder")
    @ResponseBody
    public CommonResponse<ProduceOrder> insertProduceOrder(@RequestBody ProduceOrder produceOrder){
        return produceOrderService.insertProduceOrder(produceOrder);
    }
    //删除一条农产品订单
    @DeleteMapping("orderid/{orderid}")
    @ResponseBody
    public CommonResponse<ProduceOrder> deleteProduceOrderByOrderId(@PathVariable("orderid") int orderId){
        return produceOrderService.deleteProduceOrderByOrderId(orderId);
    }
    //修改一条订单信息
    @PutMapping(value="produceorders/produceorder",consumes ="application/json")//带上请求头否则规范了,前台要传递json格式的参数
    @ResponseBody
    public CommonResponse<ProduceOrder> updateProduceOrder(@RequestBody ProduceOrder produceOrder){
        return produceOrderService.updateProduceOrder(produceOrder);
    }

}
